package com.example.framelib.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;


import com.daimajia.numberprogressbar.NumberProgressBar;
import com.example.framelib.R;


/**
 * Created by zhang on 2017/6/6.
 */

public class NumberProgressDialog extends Dialog {

    NumberProgressBar npb;

    public NumberProgressDialog(Context context) {
        this(context, R.style.progress_dialog_style);

    }

    public NumberProgressDialog(Context context, int themeResId) {
        super(context, themeResId);
        initView(context);
    }

    private void initView(Context context) {
        LinearLayout root = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.layout_number_progress_dialog, null);
        npb = (NumberProgressBar) root.findViewById(R.id.npb);
        setContentView(root);

        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        lp.x = 0; // 新位置X坐标
        lp.y = -20; // 新位置Y坐标
        root.measure(0, 0);
        lp.width = root.getMeasuredWidth();
        lp.height = root.getMeasuredHeight();
        lp.alpha = 9f; // 透明度
        dialogWindow.setAttributes(lp);
    }

    public void setProgress(int progress){
        if (npb != null) {
            npb.setProgress(progress);
        }

    }

}
